package org.example.controller;

import org.example.bean.Ship;
import org.example.service.Impl.ShipServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ShipController {
    @Autowired
    ShipServise shipServise;
    @RequestMapping("/Shiplist.do")
    @ResponseBody   //1、修饰当前方法返回类型为JSON
    public List<Ship> getAll(){  //2、将需要转换成json格式的对象直接返回
        List<Ship> list =  shipServise.getAll();
        System.out.println("打印SHIP表");
        return list;
    }
    @RequestMapping("/delete2.do")
    public void delete(int id){
        shipServise.del(id);
    }
    @RequestMapping("/test2.do")
    public String add( @RequestParam("name") String name,@RequestParam("uname") String uname,@RequestParam("tel") long tel
    ,@RequestParam("mail") String mail,@RequestParam("text") String text
    ){
        Ship ship=new Ship();
        ship.setName(name);
        ship.setMail(mail);
        ship.setTel(tel);
        ship.setText(text);
        ship.setUname(uname);
        shipServise.add(ship);
        return "/船只管理";
    }
    @RequestMapping("/update3.do")
    public String update(@RequestParam("id")int id,@RequestParam("name") String name,@RequestParam("uname") String uname,@RequestParam("tel") long tel
            ,@RequestParam("mail") String mail,@RequestParam("text") String text){
        Ship ship=new Ship();
        ship.setUname(uname);
        ship.setName(name);
        ship.setMail(mail);
        ship.setText(text);
        ship.setTel(tel);
        shipServise.update(ship);
        return"供应商管理";
    }
}
